﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using QuickPrompt.DomainModel.Identity;
using RedandBlue.RepositoryPattern.EF6;

namespace QuickPrompt.DomainModel
{
    public sealed class QuickNote : Entity
    {
        public QuickNote()
        {
            Prompts = new List<Prompt>();
        }

        [Key, ScaffoldColumn(false), Column(Order = 1), DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int Id { get; set; }

        [Column(Order = 2),
        Required(ErrorMessage = "{0} is required"),
        StringLength(150, MinimumLength = 2, ErrorMessage = "Min {1} - Max {0} characters is required"),
        Display(Name = "Name"), Index("IX_QuickNoteByUser", 2, IsUnique = true)]
        public string Name { get; set; }

        [Column(Order = 3),
        StringLength(500, MinimumLength = 2, ErrorMessage = "Min {1} - Max {0} characters is required"),
        Display(Name = "Additional Info"), DataType(DataType.MultilineText)]
        public string Description { get; set; }

        [Required(ErrorMessage = "{0} is required"),
       ScaffoldColumn(false), Index("IX_QuickNoteByUser", 1, IsUnique = true)]
        public string UserGuid { get; set; }

        [Column(Order = 6),
        Required(ErrorMessage = "{0} is required"),
        //RegularExpression(@"\d{2,2}/\d{2,2}/\d{4,4} \d{2,2}:\d{2,2}:\d{2,2}", ErrorMessage = "Invalid {0}"),
        Display(Name = "Start Date")]
        public DateTime StartDateUtc { get; set; }

        [Column(Order = 7),
        //RegularExpression(@"\d{2,2}/\d{2,2}/\d{4,4} \d{2,2}:\d{2,2}:\d{2,2}", ErrorMessage = "Invalid {0}"),
        Display(Name = "End Date")]
        public DateTime EndDateUtc { get; set; }

        [Display(Name = "Created On")]
        [Editable(false), ScaffoldColumn(false)]
        public new DateTime DateCreatedUtc { get; set; } = DateTime.UtcNow;

        [Display(Name = "Status"), ScaffoldColumn(false)]
        public new bool IsActive { get; set; }

        [ForeignKey("UserGuid")]
        public User User { get; set; }
        public ICollection<Prompt> Prompts { get; set; }
    }
}
